package com.jic.member.controller.rest;

import com.jic.common.base.vo.AdminOperate;
import com.jic.common.base.vo.RestResult;
import com.jic.member.entity.model.EventListenerContent;
import com.jic.member.request.EventListenerRequest;
import com.jic.member.service.EventListenerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description: RealTimePriceRestController
 * date: 2020/4/10 10:22
 * author: wangys
 * version: 1.0
 */
@RestController
@RequestMapping("/rest/eventListner")
@Slf4j
public class EventListnerRestController {

    @Autowired
    EventListenerService eventListenerService;

    @PostMapping("processEvent")
    public RestResult processEvent(@RequestBody EventListenerRequest request) {
        AdminOperate adminOperate = request.getAdminOperate();
        EventListenerContent eventListenerContent = new EventListenerContent()
                .setEventCode(request.getEventCode())
                .setEventType(request.getEventType())
                .setThirdUserId(request.getThirdUserId())
                .setParam(request.getParam());
        if(adminOperate != null){
            eventListenerContent.setDeptIds(adminOperate.getDeptIds())
            .setDeptType(adminOperate.getDeptType().getCode());
        }
        eventListenerService.processEvent(eventListenerContent);
        return RestResult.success(null);
    }
}
